# Maintainer: Felix Xing (Felixaszx) <felixaszx@outlook.com>

_realname=fastgltf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.0
pkgrel=1
pkgdesc="fastgltf is a speed and usability focused glTF 2.0 library written in modern C++17 with minimal dependencies (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/spnda/fastgltf"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-simdjson")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/spnda/${_realname}/archive/v${pkgver}${_realname}-${pkgver}.tar.gz")
sha256sums=('0bc88a0858c88d94306443946a5a1606118b7d5e4960f1e6186a3632e9df38fb')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

   MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "${_realname}-${pkgver}/build-${MSYSTEM}"
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
